Trò chơi Angry Birds trong UNITY Engine
31.689 lượt xem;
1 using UnityEngine;
2 using System.Collections;
3
4
5 public class GoTweenChain : AbstractGoTweenCollection
6 {
7 public GoTweenChain() : this(new GoTweenCollectionConfig()) {}
8 public GoTweenChain(GoTweenCollectionConfig config) : base(config) {}
9
10 #region internal Chain management
11
12 private void append( TweenFlowItem item )
13 {
14 // early out for invalid items
15 if( item.tween != null && !item.tween.isValid() )
16 return;
17
18 if( float.IsInfinity( item.duration ) )
19 {
20 Debug.LogError( "adding a Tween with infinite iterations to a TweenChain is not permitted" );
21 return;
22 }
23
24 if ( item.tween != null )
25 {
26 if ( item.tween.isReversed != isReversed )
27 {
28 Debug.LogError( "adding a Tween that doesn't match the isReversed property of the TweenChain is not permitted." );
29 return;
30 }
31
32 // ensure the tween isnt already live
33 Go.removeTween(item.tween);
34
35 // ensure that the item is marked to play.
36 item.tween.play();
37 }
38
39 _tweenFlows.Add( item );
40
41 // update the duration and total duration
42 duration += item.duration;
43
44 if( iterations < 0 )
45 totalDuration = float.PositiveInfinity;
46 else
47 totalDuration = duration * iterations;
48 }
49
50
51 private void prepend( TweenFlowItem item )
52 {
53 // early out for invalid items
54 if( item.tween != null && !item.tween.isValid() )
55 return;
56
57 if( float.IsInfinity( item.duration ) )
58 {
59 Debug.LogError( "adding a Tween with infinite iterations to a TweenChain is not permitted" );
60 return;
61 }
62
63 if ( item.tween != null )
64 {
65 if ( item.tween.isReversed != isReversed )
66 {
67 Debug.LogError( "adding a Tween that doesn't match the isReversed property of the TweenChain is not permitted." );
68 return;
69 }
70
71 // ensure the tween isnt already live
72 Go.removeTween( item.tween );
73
74 // ensure that the item is marked to play.
75 item.tween.play();
76 }
77
78 // fix all the start times on our previous chains
79 foreach( var flowItem in _tweenFlows )
80 flowItem.startTime += item.duration;
81
82 _tweenFlows.Insert( 0, item );
83
84 // update the duration and total duration
85 duration += item.duration;
86
87 if ( iterations < 0 )
88 totalDuration = float.PositiveInfinity;
89 else
90 totalDuration = duration * iterations;
91 }
92
93 #endregion
94
95
96 #region Chain management
97
98 /// <summary>
99 /// appends a Tween at the end of the current flow
100 /// </summary>
101 public GoTweenChain append( AbstractGoTween tween )
102 {
103 var item = new TweenFlowItem( duration, tween );
104 append( item );
105
106 return this;
107 }
108
109
110 /// <summary>
111 /// appends a delay to the end of the current flow
112 /// </summary>
113 public GoTweenChain appendDelay( float delay )
114 {
115 var item = new TweenFlowItem( duration, delay );
116 append( item );
117
118 return this;
119 }
120
121
122 /// <summary>
123 /// adds a Tween to the front of the flow
124 /// </summary>
125 public GoTweenChain prepend( AbstractGoTween tween )
126 {
127 var item = new TweenFlowItem( 0, tween );
128 prepend( item );
129
130 return this;
131 }
132
133
134 /// <summary>
135 /// adds a delay to the front of the flow
136 /// </summary>
137 public GoTweenChain prependDelay( float delay )
138 {
139 var item = new TweenFlowItem( 0, delay );
140 prepend( item );
141
142 return this;
143 }
144
145 #endregion
146
147 }
2 using System.Collections;
3
4
5 public class GoTweenChain : AbstractGoTweenCollection
6 {
7 public GoTweenChain() : this(new GoTweenCollectionConfig()) {}
8 public GoTweenChain(GoTweenCollectionConfig config) : base(config) {}
9
10 #region internal Chain management
11
12 private void append( TweenFlowItem item )
13 {
14 // early out for invalid items
15 if( item.tween != null && !item.tween.isValid() )
16 return;
17
18 if( float.IsInfinity( item.duration ) )
19 {
20 Debug.LogError( "adding a Tween with infinite iterations to a TweenChain is not permitted" );
21 return;
22 }
23
24 if ( item.tween != null )
25 {
26 if ( item.tween.isReversed != isReversed )
27 {
28 Debug.LogError( "adding a Tween that doesn't match the isReversed property of the TweenChain is not permitted." );
29 return;
30 }
31
32 // ensure the tween isnt already live
33 Go.removeTween(item.tween);
34
35 // ensure that the item is marked to play.
36 item.tween.play();
37 }
38
39 _tweenFlows.Add( item );
40
41 // update the duration and total duration
42 duration += item.duration;
43
44 if( iterations < 0 )
45 totalDuration = float.PositiveInfinity;
46 else
47 totalDuration = duration * iterations;
48 }
49
50
51 private void prepend( TweenFlowItem item )
52 {
53 // early out for invalid items
54 if( item.tween != null && !item.tween.isValid() )
55 return;
56
57 if( float.IsInfinity( item.duration ) )
58 {
59 Debug.LogError( "adding a Tween with infinite iterations to a TweenChain is not permitted" );
60 return;
61 }
62
63 if ( item.tween != null )
64 {
65 if ( item.tween.isReversed != isReversed )
66 {
67 Debug.LogError( "adding a Tween that doesn't match the isReversed property of the TweenChain is not permitted." );
68 return;
69 }
70
71 // ensure the tween isnt already live
72 Go.removeTween( item.tween );
73
74 // ensure that the item is marked to play.
75 item.tween.play();
76 }
77
78 // fix all the start times on our previous chains
79 foreach( var flowItem in _tweenFlows )
80 flowItem.startTime += item.duration;
81
82 _tweenFlows.Insert( 0, item );
83
84 // update the duration and total duration
85 duration += item.duration;
86
87 if ( iterations < 0 )
88 totalDuration = float.PositiveInfinity;
89 else
90 totalDuration = duration * iterations;
91 }
92
93 #endregion
94
95
96 #region Chain management
97
98 /// <summary>
99 /// appends a Tween at the end of the current flow
100 /// </summary>
101 public GoTweenChain append( AbstractGoTween tween )
102 {
103 var item = new TweenFlowItem( duration, tween );
104 append( item );
105
106 return this;
107 }
108
109
110 /// <summary>
111 /// appends a delay to the end of the current flow
112 /// </summary>
113 public GoTweenChain appendDelay( float delay )
114 {
115 var item = new TweenFlowItem( duration, delay );
116 append( item );
117
118 return this;
119 }
120
121
122 /// <summary>
123 /// adds a Tween to the front of the flow
124 /// </summary>
125 public GoTweenChain prepend( AbstractGoTween tween )
126 {
127 var item = new TweenFlowItem( 0, tween );
128 prepend( item );
129
130 return this;
131 }
132
133
134 /// <summary>
135 /// adds a delay to the front of the flow
136 /// </summary>
137 public GoTweenChain prependDelay( float delay )
138 {
139 var item = new TweenFlowItem( 0, delay );
140 prepend( item );
141
142 return this;
143 }
144
145 #endregion
146
147 }